package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Objects;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AppTicketMapper;
import com.ruoyi.system.domain.AppTicket;
import com.ruoyi.system.service.IAppTicketService;

/**
 * 门票信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@Service
public class AppTicketServiceImpl implements IAppTicketService 
{
    @Autowired
    private AppTicketMapper appTicketMapper;

    /**
     * 查询门票信息
     * 
     * @param ticketId 门票信息主键
     * @return 门票信息
     */
    @Override
    public AppTicket selectAppTicketByTicketId(Long ticketId)
    {
        return appTicketMapper.selectAppTicketByTicketId(ticketId);
    }

    /**
     * 查询门票信息列表
     * 
     * @param appTicket 门票信息
     * @return 门票信息
     */
    @Override
    public List<AppTicket> selectAppTicketList(AppTicket appTicket)
    {
        return appTicketMapper.selectAppTicketList(appTicket);
    }

    /**
     * 新增门票信息
     * 
     * @param appTicket 门票信息
     * @return 结果
     */
    @Override
    public int insertAppTicket(AppTicket appTicket)
    {
        //根据门票日期和类型查询是否存在
        AppTicket ticket = appTicketMapper.selectAppTicketByTicketTypeAndDate(appTicket.getTicketType(),appTicket.getTicketDate());
        if (Objects.nonNull(ticket)) {
            throw new ServiceException("该门票信息已存在");
        }
        appTicket.setCreateTime(DateUtils.getNowDate());
        return appTicketMapper.insertAppTicket(appTicket);
    }

    /**
     * 修改门票信息
     * 
     * @param appTicket 门票信息
     * @return 结果
     */
    @Override
    public int updateAppTicket(AppTicket appTicket)
    {
        appTicket.setUpdateTime(DateUtils.getNowDate());
        return appTicketMapper.updateAppTicket(appTicket);
    }

    /**
     * 批量删除门票信息
     * 
     * @param ticketIds 需要删除的门票信息主键
     * @return 结果
     */
    @Override
    public int deleteAppTicketByTicketIds(Long[] ticketIds)
    {
        return appTicketMapper.deleteAppTicketByTicketIds(ticketIds);
    }

    /**
     * 删除门票信息信息
     * 
     * @param ticketId 门票信息主键
     * @return 结果
     */
    @Override
    public int deleteAppTicketByTicketId(Long ticketId)
    {
        return appTicketMapper.deleteAppTicketByTicketId(ticketId);
    }
}
